<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>饼图：series type = pie</title>
  <script src="./echarts.js"></script>
  <script src="./data/AQIData.js"></script>
  <style lang="css">
    #chart1, #chart2 {
      width: 100%;
      height: 668px;
      border: 1px solid red;
      float: left;
    }
  </style>
</head>
<body>
  <div id="chart1"></div>

  <script>
    const myChart1 = echarts.init(document.getElementById('chart1'));

    myChart1.setOption({
      backgroundColor: '#2c343c',
      title: {
        text: '饼图',
        left: 'center',
        top: 20,
        textStyle: {
          color: '#ccc',
          fontSize: 30,
        }
      },
      legend: {
        orient: 'vertical',
        textStyle: {
          color: '#ccc',
          fontSize: 20,
        },
        top: 20,
        right: 20,
      },
      tooltip: {
        formatter: '{a} <br/>{b} : {c} ({d}%)'
      },
      series: [
        {
          name: '访问来源',
          type: 'pie',
          data: [
            { value: 335, name: '直接访问' },
            { value: 310, name: '邮件营销' },
            { value: 280, name: '联盟广告' },
            { value: 360, name: '视频广告' },
            { value: 120, name: '搜索引擎' },
          ].sort((a, b) => a.value - b.value), // 排序
          legendHoverLink: true,
          hoverAnimation: true,
          hoverOffset: 50, // hover便宜放大效果
          selectedMode: 'single',
          selectedOffset: 80,
          clockWise: true, // 是否顺时针
          startAngle: 0, // 起始角度
          // minAngle: 20,
          minShowLabelAngle: 50, // 不起作用
          roseType: 'radius', // 是否展示成南丁格尔图,有2中模式 radius、area
          animation: true,
          avoidLabelOverlap: true, // 是否开启避免label重叠
          label: {
            show: true,
            position: 'outside',
            fontSize: 16,
          },
          labelLine: {
            show: true,
            length: 20, // 这里的length时没拐弯的那段线长度, 但是值有问题不一定显示20，或许百分比？
            length2: 20,
            smooth: false,
            lineStyle: {
              color: '#ccc',
              width: 2,
              type: 'solid',
            },
          },
          itemStyle: {
            borderColor: 'red',
            borderWidth: 2,
          },
          emphasis: {
            label: {
              fontSize: 20,
            },
            labelLine: {
              lineStyle: {
                color: 'yellow'
              }
            },
            itemStyle: {
              borderWidth: 5,
            }
          },
          center: ['50%', '50%'],
          radius: '75%', // 圆半径大小，比例相对于容器
          radius: ['65%', '20%'], // 给两个值分别时内半径和外半径，可以实现圆环
          roseType: false,
          label: {
            position: 'inside'
          }
        }
      ],
    })
  </script>
</body>
</html>